package com.shengtsource.boot.application;

import org.apache.catalina.LifecycleException;
import org.apache.catalina.connector.Connector;
import org.apache.catalina.startup.Tomcat;

import javax.servlet.ServletException;;

/**
 * SpringBoot应用启动类
 * 自动创建和启动tomcat实例
 * @author shengtsource
 */
public class SpringApplication {
    public void run(String... args) {
        //创建Tomcat实例
        Tomcat tomcat = new Tomcat();
        //设置Tomcat端口号
        tomcat.setPort(8080);
        try {
            tomcat.addWebapp("/","D://");
            //启动tomcat
            tomcat.start();
            //异步请求等待
            tomcat.getServer().await();;
        } catch (ServletException e) {
            e.printStackTrace();
        } catch (LifecycleException e) {
            e.printStackTrace();
        }
    }
}
